package predicate

type AggregateOp string

func (op AggregateOp) String() string {
	return string(op)
}

var (
	SUM AggregateOp = "SUM"
	MIN AggregateOp = "MIN"
	MAX AggregateOp = "MAX"
	AVG AggregateOp = "AVG"
)

type Aggregate struct {
	Column Column
	Op     AggregateOp
	Alias  string
}

func (a Aggregate) alias() {}

func (a Aggregate) expr() {

}

func (a Aggregate) selectable() {
}

func (a Aggregate) As(alias string) Aggregate {
	return Aggregate{
		Column: a.Column,
		Op:     a.Op,
		Alias:  alias,
	}
}

func (a Aggregate) Lt(val any) Predicate {
	return Predicate{
		Op:    OpLt,
		Left:  a,
		Right: ValueOf(val),
	}
}

func (a Aggregate) Gt(val any) Predicate {
	return Predicate{
		Op:    OpGt,
		Left:  a,
		Right: ValueOf(val),
	}
}

func (a Aggregate) Eq(val any) Predicate {
	return Predicate{
		Op:    OpEqual,
		Left:  a,
		Right: ValueOf(val),
	}
}

func (a Aggregate) Le(val any) Predicate {
	return Predicate{
		Op:    OpLe,
		Left:  a,
		Right: ValueOf(val),
	}
}

func (a Aggregate) Ge(val any) Predicate {
	return Predicate{
		Op:    OpGe,
		Left:  a,
		Right: ValueOf(val),
	}
}

func Sum(c Column) Aggregate {
	return Aggregate{
		Column: c,
		Op:     SUM,
	}
}

func Min(c Column) Aggregate {
	return Aggregate{
		Column: c,
		Op:     MIN,
	}
}

func Max(c Column) Aggregate {
	return Aggregate{
		Column: c,
		Op:     MAX,
	}
}

func Avg(c Column) Aggregate {
	return Aggregate{
		Column: c,
		Op:     AVG,
	}
}

var _ Selectable = Aggregate{}
var _ Expression = Aggregate{}
var _ Alias = Aggregate{}
